<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI Chat Assistant</title>
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        body {
            background-color: #f8f9fa;
        }
        .chat-messages {
            height: 65vh;
            overflow-y: auto;
        }
        .user-message {
            background-color: #e3f2fd;
            border-radius: 10px;
            padding: 10px;
            margin-bottom: 10px;
        }
        .assistant-message {
            background-color: #f5f5f5;
            border-radius: 10px;
            padding: 10px;
            margin-bottom: 10px;
        }
        .message-time {
            font-size: 0.8rem;
            color: #6c757d;
        }
        .conversation-list {
            max-height: 75vh;
            overflow-y: auto;
        }
    </style>
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <div class="container">
            <a class="navbar-brand" href="{% url 'home' %}">
                <i class="fa-solid fa-robot me-2"></i>AI Chat Assistant
            </a>
            <div class="d-flex">
                {% if user.is_authenticated %}
                <span class="navbar-text me-3">
                    <i class="fa-solid fa-user me-1"></i> {{ user.username }}
                </span>
                <a href="{% url 'logout' %}" class="btn btn-outline-light">
                    <i class="fa-solid fa-right-from-bracket me-1"></i> Logout
                </a>
                {% else %}
                <a href="{% url 'login' %}" class="btn btn-outline-light">
                    <i class="fa-solid fa-right-to-bracket me-1"></i> Login
                </a>
                {% endif %}
            </div>
        </div>
    </nav>

    <div class="container mt-4">
        {% block content %}
        {% endblock %}
    </div>

    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // 自动滚动到聊天底部
        function scrollToBottom() {
            const chatContainer = document.querySelector('.chat-messages');
            if (chatContainer) {
                chatContainer.scrollTop = chatContainer.scrollHeight;
            }
        }

        // 页面加载完成后执行
        document.addEventListener('DOMContentLoaded', scrollToBottom);

        // 消息发送后执行
        document.querySelectorAll('form').forEach(form => {
            form.addEventListener('submit', scrollToBottom);
        });
    </script>
</body>
</html>